﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.DataSourcesFile;
using ESRI.ArcGIS.Geodatabase;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Display;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.DataManagementTools;
using ESRI.ArcGIS.SystemUI;

namespace WindowsFormsApp1
{
    public delegate void MyDelegate(IRasterLayer tmp);
    public partial class Form1 : Form
    {
        const double Sdx = 0.5;
        const double Sdy = 0.5;
        const double Ldx = 2;
        const double Ldy = 2;
        public enum AddState
        {
            AddMxdFile,
            AddShpFile,
            AddPointElement,
            FullMap, 
            Amplification,
            Narrow, 
            Roaming,
            AddLineElement,
            AddSurfaceElement,
            SpaceSearch,
            AddRasterElement
        }

        public AddState NowAddState;
        private ILayer nowChooseLayer;
        private IFeatureLayer NowLayer;
        private IFeatureRenderer DefineRender;
        private ISimpleMarkerSymbol MarkerSymbol;
        private ISimpleLineSymbol lineSymbol;
        private IRgbColor rgbColor;
        public Form1()
        {
            MarkerSymbol = new SimpleMarkerSymbolClass();
            lineSymbol = new SimpleLineSymbolClass();
            rgbColor = new RgbColorClass();
            nowChooseLayer = null;
            InitializeComponent();
        }
        public void Expend_Map(double dx, double dy)
        {
            IEnvelope envelope;
            envelope = MapControl1.Extent;
            envelope.Expand(dx, dy, true);
            MapControl1.Extent = envelope;
            MapControl1.Refresh();
        }

        private void DrawMap(IGeometry geometry,IElement element)
        {
            if (element == null || geometry == null) return;
            IGraphicsContainer graphicsContainer = MapControl1.Map as IGraphicsContainer;
            element.Geometry = geometry;
            graphicsContainer.AddElement(element, 0);
            MapControl1.Refresh();
        }
     
        private void UniqueValueRenderAPI(IFeatureLayer featureLayer)
        {
            UniqueValueRenderer valueRenderer = new UniqueValueRendererClass();

            ISimpleMarkerSymbol simpleMarker1 = new SimpleMarkerSymbolClass();
            ISimpleMarkerSymbol simpleMarker2 = new SimpleMarkerSymbolClass();
            ISimpleMarkerSymbol simpleMarker3 = new SimpleMarkerSymbolClass();
            IRgbColor rgbColor1 = new RgbColorClass();
            IRgbColor rgbColor2 = new RgbColorClass();
            IRgbColor rgbColor3 = new RgbColorClass();
            rgbColor1.Blue = 255;
            rgbColor2.Red = 255;
            rgbColor3.Green = 255;

            simpleMarker1.Color = rgbColor1;
            simpleMarker2.Color = rgbColor2;
            simpleMarker3.Color = rgbColor3;

            valueRenderer.AddValue("类别1", "type 1", simpleMarker1 as ISymbol);
            valueRenderer.AddValue("类别2", "type 2", simpleMarker2 as ISymbol);
            valueRenderer.AddValue("类别3", "type 3", simpleMarker3 as ISymbol);

            (featureLayer as IGeoFeatureLayer).Renderer = valueRenderer as IFeatureRenderer;
        }
        
        private void SpaceSearceAPI()
        {
            if (nowChooseLayer == null) return; 
            IFeatureLayer pFeatureLayer = nowChooseLayer as IFeatureLayer;
            IGeometry pGeometry = MapControl1.TrackRectangle();

            ISpatialFilter pSpatialFilter = new SpatialFilterClass();
            pSpatialFilter.Geometry = pGeometry;
            pSpatialFilter.SpatialRel = esriSpatialRelEnum.esriSpatialRelIntersects;

            IFeatureCursor pFeatureCursor = pFeatureLayer.Search(pSpatialFilter, false);
            IFeature pFeature = pFeatureCursor.NextFeature();

            IFeatureSelection pFeatureSelection = pFeatureLayer as IFeatureSelection;
            pFeatureSelection.CombinationMethod = esriSelectionResultEnum.esriSelectionResultNew;

            while (pFeature != null)
            {
                pFeatureSelection.Add(pFeature);
                pFeature = pFeatureCursor.NextFeature();
            }
            MapControl1.Refresh();
        }
        private void MapControl1_OnMouseDown(object sender, ESRI.ArcGIS.Controls.IMapControlEvents2_OnMouseDownEvent e)
        {
            switch (NowAddState)
            {
                case AddState.AddMxdFile:
                    string Filepath = MyTools.OpenFile("Open Map Doc", "Map Documents (*.mxd) |*.mxd");
                    if (Filepath == "") break;
                    if (MapControl1.CheckMxFile(Filepath))
                    {
                        MapControl1.LoadMxFile(Filepath, 0, Type.Missing);
                        IFeatureLayer pFeatLyr = MapControl1.get_Layer(0) as IFeatureLayer;
                        IGeoFeatureLayer pGeoFeatureL = pFeatLyr as IGeoFeatureLayer;
                        DefineRender = pGeoFeatureL.Renderer;
                        MapControl1.Refresh();
                    }
                    else
                    {
                        MessageBox.Show("打开了一个错误的文件");
                    }
                    break;

                case AddState.AddShpFile:
                    String FileName = MyTools.OpenFile("添加shp对象", "Shp file (*.shp) |*.shp");
                    IFeatureLayer featureLayer = MyTools.AddShpFile(FileName);
                    if (featureLayer == null) break;
                    ILayer layer = featureLayer as ILayer;
                    MapControl1.Map.AddLayer(layer);
                    MapControl1.Refresh();
                    axTOCControl1.Update();
                    break;

                case AddState.AddPointElement:
                    MapControl1.MousePointer = ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerCrosshair;
                    IGeometry MarkerPoint = MapControl1.ActiveView.ScreenDisplay.DisplayTransformation.ToMapPoint(e.x, e.y);
                    IMarkerElement pMarkerElement = new MarkerElementClass();
                    pMarkerElement.Symbol = MarkerSymbol;
                    
                    DrawMap(MarkerPoint, pMarkerElement as IElement);
                    break;

                case AddState.AddLineElement:
                    MapControl1.MousePointer = ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerCrosshair;
                    IGeometry polyline = MapControl1.TrackLine();
                    ILineElement lineElement = new LineElementClass();
                    lineElement.Symbol = lineSymbol;

                    DrawMap(polyline, lineElement as IElement);
                    break;

                case AddState.AddSurfaceElement:
                    MapControl1.MousePointer = ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerCrosshair;
                    IGeometry surface = MapControl1.TrackPolygon();
                    IPolygonElement polygonElement = new PolygonElementClass();
                    
                    DrawMap(surface, polygonElement as IElement);
                    break;

                case AddState.FullMap:
                    MapControl1.Extent = MapControl1.FullExtent;
                    break;

                case AddState.Narrow:
                    Expend_Map(Sdx, Sdy);
                    break;

                case AddState.Amplification:
                    Expend_Map(Ldx, Ldy);
                    break;

                case AddState.Roaming:
                    MapControl1.MousePointer = ESRI.ArcGIS.Controls.esriControlsMousePointer.esriPointerPan;
                    MapControl1.Pan();
                    break;

                case AddState.SpaceSearch:
                    SpaceSearceAPI();
                    break;

                case AddState.AddRasterElement:
                    String name = null;
                    IRasterLayer raster = MyTools.OpenDEM("打开栅格数据", ref name);
                    if (raster == null) break;
                    ILayer player = raster as ILayer;
                    MapControl1.AddLayer(player ,0);
                    MapControl1.Refresh();
                    break;
                default:
                    break;
            }
        }
        private void 放大ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            NowAddState = AddState.Amplification;
        }

        private void 缩小ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            NowAddState = AddState.Narrow;
        }

        private void 全图ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            NowAddState = AddState.FullMap;
        }

        private void 漫游ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            NowAddState = AddState.Roaming;
        }

        private void shp图层ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            NowAddState = AddState.AddShpFile;
        }

        private void 点要素ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            NowAddState = AddState.AddPointElement;
        }

        private void mxd文件ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            NowAddState = AddState.AddMxdFile;
        }

        private void 线要素ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            NowAddState = AddState.AddLineElement;
        }

        private void 面要素ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            NowAddState = AddState.AddSurfaceElement;
        }

        private void 线要素ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            lineSymbol.Style = esriSimpleLineStyle.esriSLSDash;
            lineSymbol.Color = rgbColor;
        }

        private void 面要素ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            
        }

        private void 点要素ToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            MarkerSymbol.Color = rgbColor;
            MarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSDiamond;
        }

        private void 颜色ToolStripMenuItem_Click(object sender, EventArgs e)
        {

            rgbColor.Blue = 255;
        }

        private void 唯一值符号化ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (nowChooseLayer == null) return;
            UniqueValueRenderAPI(nowChooseLayer as IFeatureLayer);
            this.MapControl1.Refresh();
        }

        private void 分级渲染ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                if (nowChooseLayer == null) return;
                IFeatureLayer pFeatLyr = nowChooseLayer as IFeatureLayer;
                //输入分级设色符号化的字段（我这里默认FID字段【高耦合,分级设色字段需为数值型】）
                string sFieldName = "demoClass";//要素类中数值型字段的名称
                int numclasses = 3; //输入分级设色的数量

                IGeoFeatureLayer pGeoFeatureL = pFeatLyr as IGeoFeatureLayer;
                object dataFrequency;
                object dataValues;

                ITable pTable = pGeoFeatureL.FeatureClass as ITable;
                ITableHistogram pTableHistogram = new BasicTableHistogram() as ITableHistogram;
                pTableHistogram.Field = sFieldName;
                pTableHistogram.Table = pTable;

                IBasicHistogram pBasicHistogram = pTableHistogram as IBasicHistogram;
                pBasicHistogram.GetHistogram(out dataValues, out dataFrequency);     //获取渲染字段的值及其出现的频率
                IClassifyGEN pClassify = new EqualInterval();
                try
                {
                    pClassify.Classify(dataValues, dataFrequency, ref numclasses);  //根据获取字段的值和出现的频率对其进行等级划分 
                }
                catch { }
                //返回一个数组
                double[] Classes = pClassify.ClassBreaks as double[];
                int ClassesCount = Classes.GetUpperBound(0);
                IClassBreaksRenderer pClassBreaksRenderer = new ClassBreaksRendererClass();
                pClassBreaksRenderer.Field = sFieldName; //设置分级字段
                pClassBreaksRenderer.BreakCount = ClassesCount; //设置分级数目
                pClassBreaksRenderer.SortClassesAscending = true;//分级后的图例是否按升级顺序排列
                                                                 //设置分级着色所需颜色带的起止颜色
                IHsvColor pFromColor = new HsvColor();
                pFromColor.Hue = 0;//黄色
                pFromColor.Saturation = 50;
                pFromColor.Value = 96;
                IHsvColor pToColor = new HsvColor();
                pToColor.Hue = 80;
                pToColor.Saturation = 100;
                pToColor.Value = 96;
                //产生颜色带对象
                IAlgorithmicColorRamp pAlgorithmicCR = MyTools.MakeColorRamp(pFromColor,pToColor,ClassesCount);

                //获得颜色
                IEnumColors pEnumColors = pAlgorithmicCR.Colors;
                List<esriSimpleMarkerStyle> lt = new List<esriSimpleMarkerStyle>();
                lt.Add(esriSimpleMarkerStyle.esriSMSCircle);
                lt.Add(esriSimpleMarkerStyle.esriSMSCross);
                lt.Add(esriSimpleMarkerStyle.esriSMSDiamond);
                lt.Add(esriSimpleMarkerStyle.esriSMSSquare);
                lt.Add(esriSimpleMarkerStyle.esriSMSX);
                //需要注意的是分级着色对象中的symbol和break的下标都是从0开始
                for (int breakIndex = 0; breakIndex < ClassesCount ; breakIndex++)
                {
                    IColor pColor = pEnumColors.Next();
                    switch (pGeoFeatureL.FeatureClass.ShapeType)
                    {
                        case esriGeometryType.esriGeometryPolygon:
                            {
                                ISimpleFillSymbol pSimpleFillS = new SimpleFillSymbol();

                                pSimpleFillS.Color = pColor;
                                pSimpleFillS.Style = esriSimpleFillStyle.esriSFSSolid;
                                ISimpleRenderer pSimpleRenderer = pGeoFeatureL as ISimpleRenderer;
                                IFillSymbol pFillSymbol = pSimpleRenderer.Symbol as IFillSymbol;
                                ILineSymbol pLineSymbol = pFillSymbol.Outline;
      
                                pSimpleFillS.Outline = pLineSymbol;
                                pClassBreaksRenderer.set_Symbol(breakIndex, pSimpleFillS as ISymbol);//设置填充符号
                                pClassBreaksRenderer.set_Break(breakIndex, Classes[breakIndex + 1]);//设定每一分级的分级断点
                                break;
                            }
                        case esriGeometryType.esriGeometryPolyline:
                            {
                                ISimpleLineSymbol pSimpleLineSymbol = new SimpleLineSymbol();
                                pSimpleLineSymbol.Color = pColor;

                                ISimpleRenderer pSimpleRenderer = pGeoFeatureL.Renderer as ISimpleRenderer;
                                ILineSymbol pLineSymbol = pSimpleRenderer as ILineSymbol;
                                pSimpleLineSymbol.Width = pLineSymbol.Width;

                                pClassBreaksRenderer.set_Symbol(breakIndex, pSimpleLineSymbol as ISymbol);
                                pClassBreaksRenderer.set_Break(breakIndex, Classes[breakIndex + 1]);
                                break;
                            }
                        case esriGeometryType.esriGeometryPoint:
                            {
                                int styletype = breakIndex % lt.Count;
                                ISimpleMarkerSymbol pSimpleMarkerSymbol = new SimpleMarkerSymbol();
                                pSimpleMarkerSymbol.Color = pColor;
                                pSimpleMarkerSymbol.Style = lt[styletype];

                                ISimpleRenderer pSimpleRenderer = pGeoFeatureL.Renderer as ISimpleRenderer;
                                ISimpleMarkerSymbol pMakerSymbol = pSimpleRenderer.Symbol as ISimpleMarkerSymbol;

                                pSimpleMarkerSymbol.Size = pMakerSymbol.Size;
                                pClassBreaksRenderer.set_Symbol(breakIndex, pSimpleMarkerSymbol as ISymbol);//设置填充符号
                                pClassBreaksRenderer.set_Break(breakIndex, Classes[breakIndex + 1]);//设定每一分级的分级断点
                                break;
                            }
                    }
                }
                pGeoFeatureL.Renderer = pClassBreaksRenderer as IFeatureRenderer;
                MapControl1.Refresh();
            }
            catch (Exception ex)
            {
                MessageBox.Show("该字段不存在或无法渲染！");
            }
        }

        private void 点密度ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                string sFieldName = "Id";
                if (nowChooseLayer == null) return;
                IGeoFeatureLayer pLayer = nowChooseLayer as IGeoFeatureLayer;
                ITable pTable = pLayer.FeatureClass as ITable;
                IQueryFilter pQueryFilter = new QueryFilterClass();
                pQueryFilter.AddField(sFieldName);
                ICursor pCursor = pTable.Search(pQueryFilter, true);

                IDataStatistics pDataStatistics = new DataStatisticsClass();
                pDataStatistics.Cursor = pCursor;//数据来源
                pDataStatistics.Field = sFieldName;

                IStatisticsResults pStatisticsResult = pDataStatistics.Statistics;
                double Dvalues = (pStatisticsResult.Minimum + pStatisticsResult.Maximum) / 10;//根据情况而定

                IDotDensityRenderer pDotDensityRenderer = new DotDensityRendererClass();

                IRendererFields pRendererField = pDotDensityRenderer as IRendererFields;
                pRendererField.AddField(sFieldName, sFieldName);

                IDotDensityFillSymbol pDotDensityFillSymbol = new DotDensityFillSymbolClass();
                pDotDensityFillSymbol.DotSize = 5;
                pDotDensityFillSymbol.BackgroundColor = MyTools.ErsiColor(255, 255, 255);
                pDotDensityFillSymbol.Color = MyTools.ErsiColor(255, 0, 0);

                ISymbolArray pSymbolArray = pDotDensityFillSymbol as ISymbolArray;
                ISimpleMarkerSymbol pMarkerSymbol = new SimpleMarkerSymbolClass();

                pMarkerSymbol.Color = MyTools.ErsiColor(0, 255, 0);
                pMarkerSymbol.Style = esriSimpleMarkerStyle.esriSMSSquare;
                pMarkerSymbol.Size = 5;
                pSymbolArray.AddSymbol(pMarkerSymbol as ISymbol);

                pDotDensityRenderer.DotDensitySymbol = pDotDensityFillSymbol;
                pDotDensityRenderer.DotValue = Dvalues;
                pDotDensityRenderer.CreateLegend();
                pLayer.Renderer = pDotDensityRenderer as IFeatureRenderer;
                MapControl1.Refresh();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void 还原ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IFeatureLayer pFeatLyr = nowChooseLayer as IFeatureLayer;
            IGeoFeatureLayer pGeoFeatureL = pFeatLyr as IGeoFeatureLayer;
            pGeoFeatureL.Renderer = DefineRender;
            MapControl1.Refresh();
        }
        private void 查询ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (nowChooseLayer == null) return;
            IFeatureLayer featureLayer = nowChooseLayer as IFeatureLayer;
            IFeatureSelection featureSelection = featureLayer as IFeatureSelection;
            try
            {
                IQueryFilter queryFilter = new QueryFilterClass();
                queryFilter.WhereClause = "FID = 1";
                featureSelection.SelectFeatures(queryFilter, esriSelectionResultEnum.esriSelectionResultNew, false);
                MapControl1.Refresh();
            }
            catch 
            {
                MessageBox.Show("查询出现错误，可能是选择了不存在的图层或是错误的表达式");
            }
        }

        private void 空间查询ToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            NowAddState = AddState.SpaceSearch;
        }

        private void 缓冲区分析ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (nowChooseLayer == null) return;
            try
            {
                IFeatureLayer pFeatureLayer = nowChooseLayer as IFeatureLayer;
                IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;

                IQueryFilter pQueryFilter = new QueryFilterClass();
                pQueryFilter.WhereClause = "FID = 2";

                IFeatureCursor pFeatureCursor = pFeatureClass.Search(pQueryFilter, false);
                IFeature pFeature = pFeatureCursor.NextFeature();

                ITopologicalOperator pTopologicalOperator = pFeature.Shape as ITopologicalOperator;
                IPolygon pPolygon = pTopologicalOperator.Buffer(2) as IPolygon;

                MapControl1.DrawShape(pPolygon);
                MapControl1.Refresh();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        //private void representationRendererToolStripMenuItem_Click(object sender, EventArgs e)
        //{
        //    esriTOCControlItem tocChoosedItem = esriTOCControlItem.esriTOCControlItemNone;
        //    IBasicMap pBasicMap = null;
        //    ILayer tocChoosedLyr = null;
        //    object pOther = new object();
        //    object pIndex = new object();
        //    axTOCControl1.GetSelectedItem(ref tocChoosedItem, ref pBasicMap, ref tocChoosedLyr, ref pOther, ref pIndex);
        //    System.Diagnostics.Debug.WriteLine(1);
        //    if (tocChoosedLyr is IGroupLayer)
        //    {
        //        ICompositeLayer compositeLyr = tocChoosedLyr as ICompositeLayer;
        //        int childLyrCount = compositeLyr.Count;
        //        System.Diagnostics.Debug.WriteLine(childLyrCount);
        //        for (int j = 0; j < childLyrCount; j++)
        //        {
        //            IFeatureLayer pFeatLayer = compositeLyr.get_Layer(j) as IFeatureLayer;
        //            IGeoFeatureLayer pGeoFeatLayer = pFeatLayer as IGeoFeatureLayer;
        //            IRepresentationRenderer pRepRenderer = new RepresentationRendererClass();
        //            pRepRenderer.InvisibleColor = MyTools.ErsiColor(255, 0, 0);
        //            pRepRenderer.DrawInvisible = true;
        //            pGeoFeatLayer.Renderer = pRepRenderer as IFeatureRenderer;
        //        }
        //    }
        //    MapControl1.Refresh();
        //}

        private void joinFieldToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form2 Dialog = new Form2();
            Dialog.Show(this);
        }

        private void axTOCControl1_OnMouseDown(object sender, ITOCControlEvents_OnMouseDownEvent e)
        {
            try
            {
                if (e.button == 2)           // 判断是不是右键点击； 1是左键，2是右键
                {
                    // 存储所点击的要素类型
                    esriTOCControlItem pItem = esriTOCControlItem.esriTOCControlItemNone;
                    // 地图对象
                    IBasicMap pMap = null;
                    // 图层对象
                    ILayer pLayer = null;
                    object unk = null;
                    object data = null;
                    // 以引用的方式传递参数，方便将值带出来
                    axTOCControl1.HitTest(e.x, e.y, ref pItem, ref pMap, ref pLayer, ref unk, ref data);
                    // 点击的要素图层；只是为了让读者知道该变量的类型，所以定义为局部变量，本来不应该在这里定义的，建议定义为全局变量，否则的话右键菜单的选项无法使用该图层的有关信息
                    IFeatureLayer pTocFeatureLayer = pLayer as IFeatureLayer;
                    // 判断是否是图层要素
                    if (pItem == esriTOCControlItem.esriTOCControlItemLayer && pTocFeatureLayer != null)
                    {
                        // 打开右键菜单，参数为当前鼠标的位置
                        NowLayer = pTocFeatureLayer;
                        contextMenuStrip1.Show(Control.MousePosition);
                    }
                }
                else if(e.button == 1)
                {
                    esriTOCControlItem pItem = esriTOCControlItem.esriTOCControlItemNone;
                    IBasicMap pMap = null;
                    ILayer pLayer = null;
                    object unk = null;
                    object data = null;
                    axTOCControl1.HitTest(e.x, e.y, ref pItem, ref pMap, ref pLayer, ref unk, ref data);

                    if (pItem == esriTOCControlItem.esriTOCControlItemLayer && pLayer != null)
                    {
                        nowChooseLayer = pLayer;
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void representationRendererToolStripMenuItemToolStripMenuItem_Click(object sender, EventArgs e)
        {
            IFeatureLayer pFeatLayer = NowLayer;
            IGeoFeatureLayer pGeoFeatLayer = pFeatLayer as IGeoFeatureLayer;
            IRepresentationRenderer pRepRenderer = new RepresentationRendererClass();
            pRepRenderer.InvisibleColor = MyTools.ErsiColor(255, 0, 0);
            pRepRenderer.DrawInvisible = true;
            pGeoFeatLayer.Renderer = pRepRenderer as IFeatureRenderer;
            MapControl1.Refresh();
        }

        private void dEM最短路径ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form3 Dialog = new Form3();
            Dialog.myEvent = new MyDelegate(frm2Event);
            Dialog.Show(this);
        }
        private void frm2Event(IRasterLayer rasterLayer)
        {
            MapControl1.AddLayer(rasterLayer as ILayer);
            MapControl1.Refresh();
        }
        private void 栅格图层ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            NowAddState = AddState.AddRasterElement;
        }
    }
}
